package com.controller;

import com.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/forward/params")
public class forwardController {
    //不能加@Response注解(@RestController=@Response+@Controller),否则会把return当作字符串返回
    /**
     * 请求转发：
     *        处理器方法返回String类型的标记:"forward:/转发的路径"
     */
    @RequestMapping("/handler01")
    public String handler04(HttpServletRequest request){
        System.out.println("handler04执行了...");
        List<User> list = new ArrayList<User>();
        list.add(new User("汤姆",18));
        list.add(new User("肉丝",20));
        list.add(new User("王五",30));
        request.setAttribute("list",list);
        //请求转发到jsp页面
        return "forward:/success.jsp";
    }

    /**
     * 重定向:
     *      处理器方法返回String类型的标记："redirect:/重定向的路径"
     */
    @RequestMapping("/handler02")
    public String handler05(){
        System.out.println("handler05执行了...");
        //重定向到baidu页面
        return "redirect://www.baidu.com";
    }
}
